<?php

namespace App\Containers\AppSection\Pledge\UI\API\Transformers\Properties;

use App\Containers\AppSection\File\UI\API\Transformers\FileTransformer;
use App\Containers\AppSection\Pledge\Models\Properties\Land;
use App\Ship\Parents\Transformers\Transformer;
use League\Fractal\Resource\Collection;

class LandTransformer extends Transformer
{
    protected array $defaultIncludes = [
        'extracts', 'documents', 'images', 'certificates'
    ];

    /**
     * @param Land $t
     * @return array
     */
    public function transform(Land $t): array
    {
        return [
            'object' => $t->getResourceKey(),
            'include' => $this->getAvailableIncludes(),
            'id' => $t->getHashedKey(),
            'address' => $t->address,
            'number' => $t->number,
            'total_area_type' => $t->total_area_type,
            'total_area' => $t->total_area,
            'land_category' => $t->land_category,
            'permitted_use' => $t->permitted_use,
            'certificate_number' => $t->certificate_number,
            'certificate_date' => $this->dateFormatter($t->certificate_date),
            'extract_egrn_from' => $this->dateFormatter($t->extract_egrn_from),
            'other_information' => $t->other_information,
        ];
    }

    public function includeImages(Land $t): Collection
    {
        return $this->collection($t->images()->get(), new FileTransformer);
    }

    public function includeExtracts(Land $t): Collection
    {
        return $this->collection($t->extracts()->get(), new FileTransformer);
    }

    public function includeDocuments(Land $t): Collection
    {
        return $this->collection($t->documents()->get(), new FileTransformer);
    }

    public function includeCertificates(Land $t): Collection
    {
        return $this->collection($t->certificates()->get(), new FileTransformer);
    }
}
